package com.wfh.aihelper.ai.controller;

import com.wfh.aihelper.ai.AiCodeHelperService;
import jakarta.annotation.Resource;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Title: CodeHelperController
 * @Author wangfenghuan
 * @Package com.wfh.aihelper.ai.controller
 * @Date 2025/7/10 19:57
 * @description:
 */
@RestController
@RequestMapping("/chat")
public class CodeHelperController {

    @Resource
    private AiCodeHelperService aiCodeHelperService;

    @GetMapping
    public Flux<ServerSentEvent<String>> chat(Long id,  String message) {
        return aiCodeHelperService.chatStream(id, message)
                .map(chunk -> ServerSentEvent.<String>builder().data(chunk).build());
    }
}
